package com.example.demo.common;

import org.apache.commons.lang3.StringUtils;

/**
 * @author zhouzq1@chinaexpressair.com
 * @title
 * @date 2021/10/27 9:56
 **/
public enum APIStateEnum {
    SUCCESS("SUCCESS", "操作成功"),
    FAILED("FAILED", "操作失败"),
    VALIDATE_FAILED("VALIDATE_FAILED", "参数校验失败"),
    UNAUTHORIZED("UNAUTHORIZED", "暂未登录或token已经过期"),
    FORBIDDEN("FORBIDDEN", "没有相关权限");

    private String code;
    private String msg;

    APIStateEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static String getContentByCode(String code) {
        if (StringUtils.isNotEmpty(code)) {
            APIStateEnum apiStateEnum = getAPIStateByCode(code);
            return apiStateEnum == null ? "" : apiStateEnum.getMsg();
        } else {
            return "";
        }
    }

    public static APIStateEnum getAPIStateByCode(String code) {
        APIStateEnum[] var1 = values();
        for (int i = 0; i < var1.length; i++) {
            APIStateEnum apiStateEnum = var1[i];
            if (apiStateEnum.getCode().equalsIgnoreCase(code)) {
                return apiStateEnum;
            }
        }

        return null;
    }
}
